﻿using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class ShowBloodSlider : MonoBehaviour {
	public GameObject bloodSlider;
	public GameObject bloodCanvas;
	GameObject colonSlider;
	Slider slider;
	Text text;
	Attribute attribute;
	// Use this for initialization
	void Start () {
		attribute = GetComponent<Attribute> ();
		bloodCanvas = GameObject.Find ("BloodCanvas");
		//这里如果用Network.将会在所有服务器和客户端上创建，从而出错
		//colonSlider = Instantiate (bloodSlider, bloodSlider.transform.position, bloodSlider.transform.rotation) as GameObject;
		colonSlider = bloodSlider;
		colonSlider.SetActive (true);
		colonSlider.GetComponent<UIFollowObj> ().TargetObject = gameObject;
		colonSlider.transform.rotation = bloodCanvas.transform.rotation;
		colonSlider.transform.parent = bloodCanvas.transform;
		text = colonSlider.GetComponentInChildren<Text> ();
		slider = colonSlider.GetComponent<Slider> ();
		slider.maxValue = attribute.maxHealth;
		slider.value = attribute.health;
		text.text = "<color=#00ff00>" + attribute.health.ToString () + "</color>/<color=#000000>"
				+ attribute.maxHealth.ToString () + "</color>";
	}
	
	// Update is called once per frame
	void Update () {
		if (!attribute) {
			return;
		}
		slider.maxValue = attribute.maxHealth;
		slider.value = attribute.health;
		text.text = "<color=#00ff00>" + attribute.health.ToString () + "</color>/<color=#000000>"
			+ attribute.maxHealth.ToString () + "</color>";
	}
	void OnHealthChanged(){
	}
}
